<template>
  <div class="register">
    <div class="register-steps">
      <el-container>
        <el-header>
          <el-steps :active="active" finish-status="success" style="margin-top: 20px">
            <el-step title="项目信息"></el-step>
            <el-step title="账号信息"></el-step>
            <el-step title="协议条款"></el-step>
          </el-steps>
        </el-header>
        <el-main>
          <el-container style="height: 550px" v-if="active===0">
            <el-main>
              <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="项目名" prop="projectName">
                  <el-input v-model="form.projectName" placeholder="请输入项目名"/>
                </el-form-item>
                <el-form-item label="项目地点" prop="projectLocation">
                  <el-input v-model="form.projectLocation" placeholder="请输入项目地点"/>
                </el-form-item>
                <el-form-item label="项目地址" prop="projectAddress">
                  <el-input v-model="form.projectAddress" placeholder="请输入项目地址"/>
                </el-form-item>
                <el-form-item label="项目类别" prop="porjectType">
                  <el-input v-model="form.porjectType" placeholder="请输入项目类别"/>
                </el-form-item>
                <el-form-item label="建设单位名称" prop="companyName">
                  <el-input v-model="form.companyName" placeholder="请输入建设单位名称"/>
                </el-form-item>
                <el-form-item label="社会信用代码" prop="socialCreditCode">
                  <el-input v-model="form.socialCreditCode" placeholder="请输入社会信用代码"/>
                </el-form-item>
                <el-form-item label="建设单位地址" prop="constructionUnitAddress">
                  <el-input v-model="form.constructionUnitAddress" placeholder="请输入建设单位地址"/>
                </el-form-item>
                <el-form-item label="归属档案馆" prop="archivesBelong">
                  <el-input v-model="form.archivesBelong" placeholder="请输入归属档案馆"/>
                </el-form-item>
                <el-form-item label="责任人" prop="responsiblePerson">
                  <el-input v-model="form.responsiblePerson" placeholder="请输入责任人"/>
                </el-form-item>
                <el-form-item label="责任人电话" prop="responsiblePersonPhone">
                  <el-input v-model="form.responsiblePersonPhone" placeholder="请输入责任人电话"/>
                </el-form-item>
                <el-form-item label="档案员" prop="filer">
                  <el-input v-model="form.filer" placeholder="请输入档案员"/>
                </el-form-item>
                <el-form-item label="档案员电话" prop="filerNumber">
                  <el-input v-model="form.filerNumber" placeholder="请输入档案员电话"/>
                </el-form-item>
                <el-form-item label="立项批准单位" prop="projectApprovalUnit">
                  <el-input v-model="form.projectApprovalUnit" placeholder="请输入立项批准单位"/>
                </el-form-item>
                <el-form-item label="设计单位" prop="designUnit">
                  <el-input v-model="form.designUnit" placeholder="请输入设计单位"/>
                </el-form-item>
                <el-form-item label="勘察单位" prop="surveyUnit">
                  <el-input v-model="form.surveyUnit" placeholder="请输入勘察单位"/>
                </el-form-item>
                <el-form-item label="监理单位" prop="supervisionUnit">
                  <el-input v-model="form.supervisionUnit" placeholder="请输入监理单位"/>
                </el-form-item>
                <el-form-item label="施工单位" prop="constructionUnit">
                  <el-input v-model="form.constructionUnit" placeholder="请输入施工单位"/>
                </el-form-item>
                <el-form-item label="设计号" prop="designNumber">
                  <el-input v-model="form.designNumber" placeholder="请输入设计号"/>
                </el-form-item>
                <el-form-item label="立项批准文号" prop="projectApprovalNumber">
                  <el-input v-model="form.projectApprovalNumber" placeholder="请输入立项批准文号"/>
                </el-form-item>
                <el-form-item label="立项批准附件文件地址" prop="projectApprovalFile">
                  <file-upload :file-type="fileType" v-model="form.projectApprovalFile"/>
                </el-form-item>
                <el-form-item label="建设工程规划许可证号" prop="constructionEngineeringPlanningLicenseNumber">
                  <el-input v-model="form.constructionEngineeringPlanningLicenseNumber" placeholder="请输入建设工程规划许可证号"/>
                </el-form-item>
                <el-form-item label="建设工程规划许可证附件文件地址" prop="constructionEngineeringPlanningLicenseFile">
                  <file-upload :file-type="fileType" v-model="form.constructionEngineeringPlanningLicenseFile"/>
                </el-form-item>
                <el-form-item label="建设土地规划许可证号" prop="constructionLandPlanningLicenseNumber">
                  <el-input v-model="form.constructionLandPlanningLicenseNumber" placeholder="请输入建设土地规划许可证号"/>
                </el-form-item>
                <el-form-item label="建设土地规划许可证附件文件地址" prop="constructionLandPlanningLicenseFile">
                  <file-upload :file-type="fileType" v-model="form.constructionLandPlanningLicenseFile"/>
                </el-form-item>
                <el-form-item label="国有土地使用证号" prop="stateOwnedLandUseCertificateNumber">
                  <el-input v-model="form.stateOwnedLandUseCertificateNumber" placeholder="请输入国有土地使用证号"/>
                </el-form-item>
                <el-form-item label="国有土地使用证附件文件地址" prop="stateOwnedLandUseCertificateFile">
                  <file-upload :file-type="fileType" v-model="form.stateOwnedLandUseCertificateFile"/>
                </el-form-item>
                `
                <el-form-item label="开工日期" prop="startDate">
                  <el-date-picker clearable
                                  v-model="form.startDate"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择开工日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="竣工日期" prop="completionDate">
                  <el-date-picker clearable
                                  v-model="form.completionDate"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="请选择竣工日期">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="备注信息" prop="otherInformation">
                  <el-input v-model="form.otherInformation" placeholder="请输入备注信息"/>
                </el-form-item>
                <el-form-item label="审核状态" prop="status">
                  <el-select v-model="form.status" placeholder="请选择审核状态">
                    <el-option v-for="(item, index) in statusOptions" :key="index" :label="item.label"
                               :value="item.value" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-form>
            </el-main>
          </el-container>
          <el-form v-if="active===1" ref="registerForm" :model="registerForm" :rules="registerRules"
                   class="register-form">
            <h3 class="title">若依后台管理系统</h3>
            <el-form-item prop="username">
              <el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号">
                <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
              </el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input
                v-model="registerForm.password"
                type="password"
                auto-complete="off"
                placeholder="密码"
                @keyup.enter.native="handleRegister"
              >
                <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
              </el-input>
            </el-form-item>
            <el-form-item prop="confirmPassword">
              <el-input
                v-model="registerForm.confirmPassword"
                type="password"
                auto-complete="off"
                placeholder="确认密码"
                @keyup.enter.native="handleRegister"
              >
                <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
              </el-input>
            </el-form-item>
            <el-form-item prop="code" v-if="captchaEnabled">
              <el-input
                v-model="registerForm.code"
                auto-complete="off"
                placeholder="验证码"
                style="width: 63%"
                @keyup.enter.native="handleRegister"
              >
                <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
              </el-input>
              <div class="register-code">
                <img :src="codeUrl" @click="getCode" class="register-code-img"/>
              </div>
            </el-form-item>
            <el-form-item style="width:100%;">
              <el-button
                :loading="loading"
                size="medium"
                type="primary"
                style="width:100%;"
                @click.native.prevent="handleRegister"
              >
                <span v-if="!loading">注 册</span>
                <span v-else>注 册 中...</span>
              </el-button>
              <div style="float: right;">
                <router-link class="link-type" :to="'/login'">使用已有账户登录</router-link>
              </div>
            </el-form-item>
          </el-form>
          <el-button @click="last">上一步</el-button>
          <el-button @click="next">下一步</el-button>
        </el-main>
      </el-container>
    </div>

    <!--  底部  -->
    <div class="el-register-footer">
      <span>Copyright © 2018-2024 ruoyi.vip All Rights Reserved.</span>
    </div>
  </div>
</template>

<script>
import {getCodeImg, register} from "@/api/login";

export default {
  name: "Register_Archives",
  data() {
    const equalToPassword = (rule, value, callback) => {
      if (this.registerForm.password !== value) {
        callback(new Error("两次输入的密码不一致"));
      } else {
        callback();
      }
    };
    return {
      active: 0,
      codeUrl: "",
      registerForm: {
        username: "",
        password: "",
        confirmPassword: "",
        code: "",
        uuid: ""
      },
      fileType: ['jpg', 'jpeg', 'png', 'pdf'],
      registerRules: {
        username: [
          {required: true, trigger: "blur", message: "请输入您的账号"},
          {min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur'}
        ],
        password: [
          {required: true, trigger: "blur", message: "请输入您的密码"},
          {min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur"},
          {pattern: /^[^<>"'|\\]+$/, message: "不能包含非法字符：< > \" ' \\\ |", trigger: "blur"}
        ],
        confirmPassword: [
          {required: true, trigger: "blur", message: "请再次输入您的密码"},
          {required: true, validator: equalToPassword, trigger: "blur"}
        ],
        code: [{required: true, trigger: "change", message: "请输入验证码"}]
      },
      loading: false,
      captchaEnabled: true,
      form: {},
      rules: {
        projectName: [
          {required: true, message: "项目名不能为空", trigger: "blur"}
        ],
        projectLocation: [
          {required: true, message: "项目地点不能为空", trigger: "blur"}
        ],
        projectAddress: [
          {required: true, message: "项目地址不能为空", trigger: "blur"}
        ],
        porjectType: [
          {required: true, message: "项目类别不能为空", trigger: "change"}
        ],
        companyName: [
          {required: true, message: "建设单位名称不能为空", trigger: "blur"}
        ],
        socialCreditCode: [
          {required: true, message: "社会信用代码不能为空", trigger: "blur"}
        ],
        constructionUnitAddress: [
          {required: true, message: "建设单位地址不能为空", trigger: "blur"}
        ],
        archivesBelong: [
          {required: true, message: "归属档案馆不能为空", trigger: "blur"}
        ],
        responsiblePerson: [
          {required: true, message: "责任人不能为空", trigger: "blur"}
        ],
        responsiblePersonPhone: [
          {required: true, message: "责任人电话不能为空", trigger: "blur"}
        ],
        filer: [
          {required: true, message: "档案员不能为空", trigger: "blur"}
        ],
        filerNumber: [
          {required: true, message: "档案员电话不能为空", trigger: "blur"}
        ],
        projectApprovalUnit: [
          {required: true, message: "立项批准单位不能为空", trigger: "blur"}
        ],
        designUnit: [
          {required: true, message: "设计单位不能为空", trigger: "blur"}
        ],
        surveyUnit: [
          {required: true, message: "勘察单位不能为空", trigger: "blur"}
        ],
        supervisionUnit: [
          {required: true, message: "监理单位不能为空", trigger: "blur"}
        ],
        constructionUnit: [
          {required: true, message: "施工单位不能为空", trigger: "blur"}
        ],
        designNumber: [
          {required: true, message: "设计号不能为空", trigger: "blur"}
        ],
        projectApprovalNumber: [
          {required: true, message: "立项批准文号不能为空", trigger: "blur"}
        ],
        projectApprovalFile: [
          {required: true, message: "立项批准附件文件地址不能为空", trigger: "blur"}
        ],
        constructionEngineeringPlanningLicenseNumber: [
          {required: true, message: "建设工程规划许可证号不能为空", trigger: "blur"}
        ],
        constructionEngineeringPlanningLicenseFile: [
          {required: true, message: "建设工程规划许可证附件文件地址不能为空", trigger: "blur"}
        ],
        constructionLandPlanningLicenseNumber: [
          {required: true, message: "建设土地规划许可证号不能为空", trigger: "blur"}
        ],
        constructionLandPlanningLicenseFile: [
          {required: true, message: "建设土地规划许可证附件文件地址不能为空", trigger: "blur"}
        ],
        stateOwnedLandUseCertificateNumber: [
          {required: true, message: "国有土地使用证号不能为空", trigger: "blur"}
        ],
        stateOwnedLandUseCertificateFile: [
          {required: true, message: "国有土地使用证附件文件地址不能为空", trigger: "blur"}
        ],
        startDate: [
          {required: true, message: "开工日期不能为空", trigger: "blur"}
        ],
        completionDate: [
          {required: true, message: "竣工日期不能为空", trigger: "blur"}
        ],
        status: [
          {required: true, message: "案卷状态不能为空", trigger: "change"}
        ]
      },
      statusOptions: [{
        "label": "受理",
        "value": 1
      }, {
        "label": "驳回",
        "value": 2
      }, {
        "label": "未处理",
        "value": 3
      }],
    };
  },
  created() {
    this.getCode();
  },
  methods: {
    getCode() {
      getCodeImg().then(res => {
        this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
        if (this.captchaEnabled) {
          this.codeUrl = "data:image/gif;base64," + res.img;
          this.registerForm.uuid = res.uuid;
        }
      });
    },
    handleRegister() {
      this.$refs.registerForm.validate(valid => {
        if (valid) {
          this.loading = true;
          register(this.registerForm).then(res => {
            const username = this.registerForm.username;
            this.$alert("<font color='red'>恭喜你，您的账号 " + username + " 注册成功！</font>", '系统提示', {
              dangerouslyUseHTMLString: true,
              type: 'success'
            }).then(() => {
              this.$router.push("/login");
            }).catch(() => {
            });
          }).catch(() => {
            this.loading = false;
            if (this.captchaEnabled) {
              this.getCode();
            }
          })
        }
      });
    },
    next() {
      if (this.active < 2) this.active++;
    },
    last() {
      if (this.active > 0) this.active--;
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
.register-steps {
  width: 600px;
  height: 700px;
  background-color: floralwhite;
  justify-content: center;
}

.register {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-image: url("../assets/images/login-background.jpg");
  background-size: cover;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #707070;
}

.register-form {
  border-radius: 6px;
  background: #ffffff;
  width: 400px;
  padding: 25px 25px 5px 25px;

  .el-input {
    height: 38px;

    input {
      height: 38px;
    }
  }

  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}

.register-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}

.register-code {
  width: 33%;
  height: 38px;
  float: right;

  img {
    cursor: pointer;
    vertical-align: middle;
  }
}

.el-register-footer {
  height: 40px;
  line-height: 40px;
  position: fixed;
  bottom: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-family: Arial;
  font-size: 12px;
  letter-spacing: 1px;
}

.register-code-img {
  height: 38px;
}
</style>
